package edu.cueb.wmis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import edu.cueb.wmis.mapper.GoodMapper;
import edu.cueb.wmis.mapper.IncomebillMapper;
import edu.cueb.wmis.pojo.Good;
import edu.cueb.wmis.pojo.Incomebill;
import edu.cueb.wmis.pojo.Incomebillitem;
import edu.cueb.wmis.mapper.IncomebillitemMapper;
import edu.cueb.wmis.service.IIncomebillitemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liuzizhuo
 * @since 2021-04-19
 */
@Service
public class IncomebillitemServiceImpl extends ServiceImpl<IncomebillitemMapper, Incomebillitem> implements IIncomebillitemService {

    @Autowired
    private IncomebillitemMapper incomebillitemMapper;
    @Autowired
    private IncomebillMapper incomebillMapper;
    @Autowired
    private GoodMapper goodMapper;
    @Override
    //需要赋值billId 入库概单的id
    public boolean addInBillItem(Incomebillitem incomebillitem) {
        List<Map<String, Object>> list = incomebillMapper.selectMaps(new QueryWrapper<Incomebill>().select("max(id)"));
        Integer billId = Integer.parseInt(list.get(0).get("max(id)").toString());
        incomebillitem.setBillId(billId);
        if(1 == incomebillitemMapper.insert(incomebillitem)){
            System.out.println(incomebillitem);
            return true;
        }else{
            return false;
        }
    }



}
